/*
 * @Author: zhangweixin 
 * @Date: 2018-12-03 17:42:58 
 * @Last Modified by: zhangweixin
 * @Last Modified time: 2018-12-07 17:03:56
 */
import React,{Component} from 'react';
import {connect} from 'react-redux';
import Template from './template.jsx';
import {
  getParams
} from 'utils/utils.js';
import {getOrderList} from '../../actions/orderActions';

class OrderList extends Component{
  constructor(props){
    super(props);
    this.state={
      filters: [
        { type: "all", label: "全部",status:-2 },
        { type: "waitpay", label: "待付款", num: 0, status: 0,},
        // { type: "grouping", label: "拼团中", num: 0, status: 7, },
        { type: "shipping", label: "待发货", status: 2,},
        { type: "shipped", label: "配送中", status: 3, },
        { type: "success", label: "交易成功", status: 4, },
        // { type: "afterSale", label: "退换/售后",}
        // { type: "refund", label: "退款" }
      ],
      selectFilterType: "all",
      selectFilterIndex:0,
      page:1
    }
    this.render = Template;
    this.onNavBarClickHandler = this.onNavBarClickHandler.bind(this);
    this.onFetchOrderListHandler = this.onFetchOrderListHandler.bind(this);
  }
  componentWillMount(){
    document.title="订单列表"
  }
  componentDidMount(){
    let {search} = this.props.location;
    let queryObj = getParams(search);
    this.setState({
      selectFilterType:queryObj.type
    })
    this.onFetchOrderListHandler()
  }
  onNavBarClickHandler(e){
    let type = e.currentTarget.getAttribute("data-type");
    let index = e.currentTarget.getAttribute("data-index");
    if(type == this.state.selectFilterType) return;
    this.setState({
      selectFilterType:type,
      selectFilterIndex:index
    })
  }
  onFetchOrderListHandler(){
    let selectItem = this.state.filters[this.state.selectFilterIndex]
    let queryObj={
      status:selectItem.status,
      limit:10,
      page:this.state.page
    }
    console.log(this.props)
    // debugger
    this.props.getOrderList(queryObj)
  }
}
function mapStateToProps(state){
  return {
    orderList:state.orderList
  }
}
function mapDispatchToProps(dispatch){
  return {
    getOrderList:()=>{
      dispatch(getOrderList())
    }
  }
}
export default connect(mapStateToProps,mapDispatchToProps)(OrderList);